package com.grain.mall.goods.controller;

import com.grain.mall.goods.feign.MarketFeign;
import entity.Student;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * GoodsController
 * <p/>
 * 商品控制器
 * 测试 baseEntity 的 extraMap 属性
 * @author kmchen
 * @Date 2020/11/25 9:55
 * Copyright (c) 2018 MANJDD
 */
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private MarketFeign marketFeign;

    @GetMapping("showStudent")
    public List<Student> showStudent() {
        List<Student> students = marketFeign.showStudent();
        students.forEach(item ->{
            item.setBooks(Collections.singletonList("Math,Chinese,English"));
            Map<String, String> map = new HashMap<>();
            map.put("Math","bad");
            item.setMap(map);
        });
        List<Student> list = students.stream().map(item -> {
            Student student = new Student();
            BeanUtils.copyProperties(item, student);
//            Map<String, String> map = new HashMap<>();
//            BeanUtils.copyProperties(item.get);
            return student;
        }).collect(Collectors.toList());
        return list;
    }

}
